package com.justnow.offer.usejdk;

import javafx.beans.binding.ObjectExpression;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author justnow
 * Created on 2020-09-05
 * Description
 */
public class JdkInvocationHandler implements InvocationHandler {


    private Object target;

    public JdkInvocationHandler(Object target) {
        this.target = target;
    }

    /**
     *
     * @param proxy 代理类实例
     * @param method 被增强的方法对象
     * @param args 方法参数
     * @return
     * @throws Throwable
     */
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        String name = method.getName();
        if ("sayHello".equals(name)) {
            System.out.println("======插入前置通知======");
            method.invoke(target, args);
            System.out.println("======插入后置通知======");
        }
        return null;
    }
}
